import 'package:mobx/mobx.dart';

/// 必须, 用于生成.g文件
part 'counter.g.dart';
class Counter = CounterMobx with _$Counter;

/// 步骤:
/// 1. 创建counter.dart
/// 2. 添加 part 'counter.g.dart';
/// 3. 添加 class Counter = CounterMobx with _$Counter;
/// 4. 执行命令: flutter packages pub run build_runner build
/// 5. 删除之内再生成: flutter packages pub run build_runner build --delete-conflicting-outputs
/// 6. 实时更新.g文件: flutter packages pub run build_runner watch

/// Counter可观察对象
abstract class CounterMobx with Store {
  /// 可观察的值
  @observable int value = 0;

  /// 加法
  @action void increment() {
    value++;
  }

  /// 减法
  @action void decrement() {
    value--;
  }

  /// 设置值
  @action void set(int value) {
    this.value = value;
  }
}